﻿function FKalert(userid, statrday, endday, name) {
    var today = new Date();            //月份为0-11
    var yesterday_milliseconds = today.getTime();
    var yesterday = new Date();
    yesterday.setTime(yesterday_milliseconds);

    var strYear = yesterday.getFullYear();
    var strDay = yesterday.getDate();
    var strMonth = yesterday.getMonth() + 1;
    if (strMonth < 10) {
        strMonth = "0" + strMonth;
    }
    var strYesterday = strYear + "-" + strMonth + "-" + strDay;
    parent.ShowIframe("../Quantify/Report/lp_Report_Userlist_1.aspx?userid=" + userid + "&statrday=" + strYesterday + "&endday=" + strYesterday + "", 700, 450, name + "工作项详细");
}
function ajaxList() {
    
    if (GetDeptType(depttype)) {
       
        document.getElementById('worklist').innerHTML = "<img src=\"../../images/loading.gif\"  />";
        $.ajax({
            type: "POST",
            url: "../AjaxServer.aspx",
            dataType: 'json',
            data: "alt=deptlist&deptid=" + todaydeptid + "&depttype=" + todaydepttype + "",
            processData: false,
            timeout: '10000',
            success: function(msg) {
            
                divlist(msg);
            },
            error: function() {
                document.getElementById('worklist').innerHTML = "系统繁忙";

            }

        });
    }
    else {
        document.getElementById('worklist').innerHTML = "";
        document.getElementById('divadminUrl').innerHTML = "";
    }
}

function divlist(msg) {

    var arr = [];
    arr.push("<table  border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce' class=\"table\" valign='top'>");
    arr.push("<tr bgcolor=\"#353c44\" >");
    arr.push("<td width=\"100px\"  style='text-align: center;background-color: #d3eaef'  >");
    arr.push("<div >部门</div>");
    arr.push("</td>");
    arr.push("<td width=\"75px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >考核人数</div>");
    arr.push("</td>");

  
    arr.push("<td width=\"75px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >实际得分</div>");
    arr.push("</td>");
    arr.push("<td width=\"60px\"  style='text-align: center;background-color: #d3eaef'  >");
    arr.push("<div >平均分</div>");
    arr.push("</td>");
    arr.push("<td width=\"75px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >要求得分</div>");
    arr.push("</td>");

    arr.push("<td width=\"60px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >完成率%</div>");
    arr.push("</td>");
    arr.push("<td width=\"100px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >未达标人数</div>");
    arr.push("</td>");
    arr.push("<td width=\"120px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >(经理)昨日未部署</div>");
    arr.push("</td>");
    arr.push("<td width=\"120px\"  style='text-align: center;background-color: #d3eaef'>");
    arr.push("<div >(经理)昨日未检查</div>");
    arr.push("</td>");

    arr.push("</tr>");
    var allwork_testnumber = 0; //人数
    var work_average = 0; //平均分
    var work_standard = 0;
    var work_yestoday = 0;
    var work_deployment = 0;
    var work_total = 0;
    var work_actual_goal = 0; //实际得分
    var all = 0;

    for (var i = 0; i < msg.msg.length; i++) {
       
        if (i % 2 == 0)
            arr.push("<tr bgcolor='#FFFFFF'>");
        else
            arr.push("<tr bgcolor='#EEEDED'>");
        arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
        if (msg.depttype == '区域') {
            arr.push("<a onclick=\"workyestoday(" + msg.msg[i].work_deptid + ",'" + msg.msg[i].work_deptname + "')\">" + msg.msg[i].work_deptname + "</a>");
        }
        else {
            arr.push("<a onclick=\"worklist(" + msg.msg[i].work_deptid + ",'" + msg.msg[i].work_deptname + "')\">" + msg.msg[i].work_deptname + "</a>");
        }
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        allwork_testnumber += parseInt(msg.msg[i].work_testnumber);
        arr.push(msg.msg[i].work_testnumber);
        arr.push("</td>");

       
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(msg.msg[i].work_actual_goal);
        work_total += parseInt(msg.msg[i].work_total);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        //work_average += parseInt(msg.msg[i].work_average);
        arr.push(msg.msg[i].work_average);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(msg.msg[i].work_total);
        work_actual_goal += parseInt(msg.msg[i].work_actual_goal);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");

        if (msg.msg[i].work_total != 0) {

            arr.push(parseInt(isNaN(((msg.msg[i].work_actual_goal * 100) / msg.msg[i].work_total)) == true ? '0' : ((msg.msg[i].work_actual_goal * 100) / msg.msg[i].work_total)));
        }
        else {
            arr.push('0');
        }
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        work_standard += parseInt(msg.msg[i].work_standard);
        arr.push(msg.msg[i].work_standard);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(msg.msg[i].work_deployment);
        work_deployment += parseInt(msg.msg[i].work_deployment);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6' style='color:red'>");
        arr.push(msg.msg[i].work_yestoday == "" ? "0" : msg.msg[i].work_yestoday);

        work_yestoday += parseInt(msg.msg[i].work_yestoday == "" ? "0" : msg.msg[i].work_yestoday);
        arr.push("</td>");

        arr.push("</tr>");
    }
    if (work_total != 0) {
        all = parseInt(isNaN(work_actual_goal * 100 / work_total) == true ? '0' : work_actual_goal * 100 / work_total);
    }
    else {
        all = 0;
    }
    arr.push("<tr  bgcolor='#FFFFFF'>");
    arr.push("<td class='STYLE6'>");
    arr.push("总计：");
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(allwork_testnumber);
    arr.push("</td>");
   
    arr.push("<td class='STYLE6'>");
    arr.push(work_actual_goal);
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(changeTwoDecimal_f(work_actual_goal / allwork_testnumber));
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(work_total);
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(all);
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(work_standard);
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(work_deployment);
    arr.push("</td>");
    arr.push("<td class='STYLE6'>");
    arr.push(isNaN(work_yestoday) == true ? "0" : work_yestoday);
    arr.push("</td>");

    arr.push("</tr>");
    arr.push("</table>");

    document.getElementById('worklist').innerHTML = arr.join('');
   
  
       
}

function workyestoday(deptid, deptname) {
    var today = new Date();            //月份为0-11
    var yesterday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24;
    var yesterday = new Date();
    yesterday.setTime(yesterday_milliseconds);

    var strYear = yesterday.getFullYear();
    var strDay = yesterday.getDate();
    var strMonth = yesterday.getMonth() + 1;
    if (strMonth < 10) {
        strMonth = "0" + strMonth;
    }

    var strYesterday = strYear + "-" + strMonth + "-" + strDay;

    parent.closeTab("昨日 " + deptname);
    // self.parent.parent.addTab(deptname, "../Quantify/lp_Report_list.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");
    parent.addTab("昨日 " + deptname, "../Quantify/lp_YesterDay.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");
}


//点击区域tab
function worklist(deptid, deptname) {
    var today = new Date();            //月份为0-11
    var yesterday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24;
    var yesterday = new Date();
    yesterday.setTime(yesterday_milliseconds);

    var strYear = yesterday.getFullYear();
    var strDay = yesterday.getDate();
    var strMonth = yesterday.getMonth() + 1;
    if (strMonth < 10) {
        strMonth = "0" + strMonth;
    }

    var strYesterday = strYear + "-" + strMonth + "-" + strDay;

    parent.closeTab("昨日 " + deptname);
    parent.addTab("昨日 " + deptname, "../Quantify/Report/lp_Report_addresslist.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");


}
//js保留2位小数（强制）  
function changeTwoDecimal_f(x) {
    var f_x = parseFloat(x);
    if (isNaN(f_x)) {
        //alert('function:changeTwoDecimal->parameter error');
        return false;
    }
    var f_x = Math.round(x * 100) / 100;
    var s_x = f_x.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
        s_x += '0';
    }
    return s_x;
}

function setTab(m, n) {
    var tli = document.getElementById("menu" + m).getElementsByTagName("li");
    var mli = document.getElementById("main" + m).getElementsByTagName("ul");
    if (depttype != "后勤") {
        for (i = 0; i < tli.length-1; i++) {

            tli[i].className = i == n ? "libg" : "";
            mli[i].style.display = (i == n ? "block" : "none");

        }
    }
    else {

        for (i = 0; i < tli.length; i++) {
            tli[i].style.display = "none";
        }
        tli[1].style.display = "block";
        tli[3].style.display = "block";
        ajaxList(); 
        yesdayList();
    }
    divReplynumber(); //回复个数
}

function FKalert(userid, statrday, endday, name) {
    var today = new Date();            //月份为0-11
    var yesterday_milliseconds = today.getTime();
    var yesterday = new Date();
    yesterday.setTime(yesterday_milliseconds);

    var strYear = yesterday.getFullYear();
    var strDay = yesterday.getDate();
    var strMonth = yesterday.getMonth() + 1;
    if (strMonth < 10) {
        strMonth = "0" + strMonth;
    }
    var strYesterday = strYear + "-" + strMonth + "-" + strDay;
    parent.ShowIframe("../Quantify/Report/lp_Report_Userlist_1.aspx?userid=" + userid + "&statrday=" + strYesterday + "&endday=" + strYesterday + "", 700, 450, name + "工作项详细");
}



//        function textCounter(counter, maxlimit, linecounter) {
//            var total = '<%=total %>';
//            var Actual_Goal = '<%=Actual_Goal %>';

//            var percentage = parseInt((Actual_Goal / total) * 100);
//        }





window.onload = function() {
    if (depttype != "后勤") {
        setTab(0, 0);
    } else {
        setTab(0, 1);
    }
    GetAdminUrl();
    
}
//function ajaxList() {

//    if (depttype == '营业大部' || depttype == '营业部' || depttype == '区域') {
//        $.ajax({
//            type: "POST",
//            url: "../AjaxServer.aspx",
//            dataType: 'json',
//            data: "alt=deptlist&deptid=" + deptid + "&depttype=" + depttype + "",
//            processData: false,
//            timeout: '10000',
//            success: function(msg) {

//                divlist(msg);

//            },
//            error: function() {
//                document.getElementById('worklist').innerHTML = "系统繁忙";

//            }

//        });
//    }
//    else {
//        document.getElementById('worklist').innerHTML = "";

//    }
//}



function workyestoday(deptid, deptname) {
    var today = new Date();            //月份为0-11
    var yesterday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24;
    var yesterday = new Date();
    yesterday.setTime(yesterday_milliseconds);

    var strYear = yesterday.getFullYear();
    var strDay = yesterday.getDate();
    var strMonth = yesterday.getMonth() + 1;
    if (strMonth < 10) {
        strMonth = "0" + strMonth;
    }

    var strYesterday = strYear + "-" + strMonth + "-" + strDay;

    parent.parent.closeTab("昨日 " + deptname);
    // self.parent.parent.addTab(deptname, "../Quantify/lp_Report_list.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");
    parent.parent.addTab("昨日 " + deptname, "../Quantify/lp_YesterDay.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");
}


//点击区域tab
function worklist(deptid, deptname) {
    var today = new Date();            //月份为0-11
    var yesterday_milliseconds = today.getTime() - 1000 * 60 * 60 * 24;
    var yesterday = new Date();
    yesterday.setTime(yesterday_milliseconds);

    var strYear = yesterday.getFullYear();
    var strDay = yesterday.getDate();
    var strMonth = yesterday.getMonth() + 1;
    if (strMonth < 10) {
        strMonth = "0" + strMonth;
    }

    var strYesterday = strYear + "-" + strMonth + "-" + strDay;

    parent.parent.closeTab("昨日 " + deptname);
    parent.parent.addTab("昨日 " + deptname, "../Quantify/Report/lp_Report_addresslist.aspx?type=1&deptname=" + escape(deptname) + "&deptid=" + deptid + "&statrday='" + strYesterday + "'&endday='" + strYesterday + "'", "icon-nav");


}
//js保留2位小数（强制）  
function changeTwoDecimal_f(x) {
    var f_x = parseFloat(x);
    if (isNaN(f_x)) {
        //alert('function:changeTwoDecimal->parameter error');
        return false;
    }
    var f_x = Math.round(x * 100) / 100;
    var s_x = f_x.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 2) {
        s_x += '0';
    }
    return s_x;
}

function yesdayList() {

    if (GetDeptType(depttype)) {
        
        document.getElementById('divchart').innerHTML = "<img src=\"../../images/loading.gif\"  />";
        $.ajax({
            type: "POST",
            url: "../AjaxServer.aspx",
            dataType: 'json',
            data: "alt=chart&deptid=" + todaydeptid + "&depttype=" + todaydepttype + "",
            processData: false,
            timeout: '10000',
            success: function(msg) {
                chartlist(msg);
            },
            error: function() {
                document.getElementById('divchart').innerHTML = "系统繁忙";
            }

        });
    }
    function chartlist(msg) {
        var chart;

        var yesdaychart = "";
        if (msg.msg.length > 0) {
            yesdaychart = "[";
            for (var i = 0; i < msg.msg.length; i++) {
                yesdaychart += "{name: '" + msg.msg[i].basisname + msg.msg[i].actual_number + "', y: " + msg.msg[i].actual_goal + ",dataLabels:'" + GetUrl(msg.msg[i].basisname) + "&deptid=" + jsdeptid + "&addDate2=" + returnYesday() + "" + "&addDate1=" + returnYesday() + "'},";
            }
            yesdaychart = yesdaychart.substring(0, yesdaychart.length - 1);
            yesdaychart += "]";
            yesdaychart = eval('' + yesdaychart + '');
//            if (depttype != '后勤') {
//                chartxs(yesdaychart, '昨日工作', 'divchart');
//            }
//            else {
                chartxsDeptlist(yesdaychart, '昨日工作', 'divchart',2);
            //}
        }
    }
}
function Commentlist()//评语
{

    if (depttype == '营业大部' || depttype == '营业部' || depttype == '区域' || depttype == '分行') {
        document.getElementById('divComment').innerHTML = "<img src=\"../../images/loading.gif\"  />";
        $.ajax({
            type: "POST",
            url: "../AjaxServer.aspx",
            dataType: 'json',
            data: "alt=commentlist&deptid=" + deptid + "&depttype=" + depttype + "",
            processData: false,
            timeout: '10000',
            success: function(msg) {
                divComment(msg);

            },
            error: function() {
                document.getElementById('divComment').innerHTML = "系统繁忙";

            }

        });
    }
    else {

    }
}
function divComment(msg) {

    var arr = [];
    arr.push("<table  border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'  class=\"table1\" valign='top' >");
    arr.push("<tr bgcolor=\"#353c44\" >");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:80px;'  >");
    arr.push("<div >评论对象</div>");
    arr.push("</td>");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:360px'>");
    arr.push("<div >评论</div>");
    arr.push("</td>");

    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:120px'>");
    arr.push("<div >日期</div>");
    arr.push("</td>");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:80px'>");
    arr.push("<div >创建者</div>");
    arr.push("</td>");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:160px'>");
    arr.push("<div >创建部门</div>");
    arr.push("</td>");
    arr.push("</td>");
    arr.push("</tr>");


    for (var i = 0; i < msg.msg.length; i++) {

        if (i % 2 == 0)
            arr.push("<tr bgcolor='#FFFFFF'>");
        else
            arr.push("<tr bgcolor='#EEEDED'>");
        arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
        arr.push(msg.msg[i].user_name);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(msg.msg[i].reply);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(msg.msg[i].txttime);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6' style='color:red'>");
        arr.push(msg.msg[i].createname);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6' style='color:red'>");
        arr.push(msg.msg[i].deptname);
        arr.push("</td>");
        arr.push("</tr>");
    }


    arr.push("</table>");

    document.getElementById('divComment').innerHTML = arr.join('');
}

function GetAdminUrl() {
    document.getElementById('divadminUrl').innerHTML = "<img src=\"../../images/loading.gif\"  />";

    $.ajax({
        type: "POST",
        url: "../AjaxServer.aspx",
        dataType: 'json',
        data: "alt=AdminUrl",
        processData: false,
        timeout: '10000',
        success: function(msg) {
            var fkstring = "";
            for (var i = 0; i < msg.msg.length; i++) {
                fkstring += "<a href=\"" + msg.msg[i].url + "\" target=\"_blank\">" + msg.msg[i].typename + "</a>&nbsp;&nbsp;";
            }
            document.getElementById('divadminUrl').innerHTML = fkstring;
        },
        error: function() {
            document.getElementById('divadminUrl').innerHTML = "系统繁忙";
        }

    });
}